package cn.wendellup.bootStrap.util;

import java.security.NoSuchAlgorithmException;
import java.util.Date;

import org.apache.log4j.spi.ErrorCode;

import cn.egame.common.util.Utils;
import cn.wendellup.bootStrap.valueobject.constants.FileUsedType;
import cn.wendellup.bootStrap.valueobject.exception.ExceptionCommon;

public class FileUtils {
	public static String getFilePath(FileUsedType fileType, long fileId,
			String fileName) throws NoSuchAlgorithmException, ExceptionCommon {
		String extName = Utils.getFileExtName(fileName);
		if (Utils.stringIsNullOrEmpty(extName))
			throw new ExceptionCommon(-1 ,
					fileType.toString());
		switch (fileType.value()) {
		case FileUsedType.GAME:
			return "gm" + Utils.toPath("/", fileId) + "/"
					+ Utils.toFileName(fileId) + "/" + fileName;
		case FileUsedType.HEAD_PHOTO:
			return "hd" + Utils.toPath("/", fileId) + "/"
					+ Utils.toFileName(fileId) + extName;
		case FileUsedType.HEAD_SML:
			return "hd/sml" + Utils.toPath("/", fileId) + "/"
					+ Utils.toFileName(fileId) + extName;	
		case FileUsedType.HEAD_MID:
			return "hd/mid" + Utils.toPath("/", fileId) + "/"
					+ Utils.toFileName(fileId) + extName;
		case FileUsedType.HEAD_BIG:
			return "hd/big" + Utils.toPath("/", fileId) + "/"
					+ Utils.toFileName(fileId) + extName;
		case FileUsedType.HEAD_BACKGROUD:
			return "hd/back" + Utils.toPath("/", fileId) + "/"
					+ Utils.toFileName(fileId) + extName;
		case FileUsedType.GAME_PHOTO:
			return "ph" + Utils.toPath("/", fileId) + "/"
					+ Utils.toFileName(fileId) + extName;
		case FileUsedType.GAME_LOGO_SML:
			return "ph/sml" + Utils.toPath("/", fileId) + "/"
					+ Utils.toFileName(fileId) + extName;
		case FileUsedType.GAME_LOGO_BIG:
			return "ph/big" + Utils.toPath("/", fileId) + "/"
					+ Utils.toFileName(fileId) + extName;	
		case FileUsedType.GAME_VIEW:
			return "ph/view" + Utils.toPath("/", fileId) + "/"
					+ Utils.toFileName(fileId) + extName;
		case FileUsedType.GAME_VIEW_SML:
            return "ph/view/sml" + Utils.toPath("/", fileId) + "/"
                    + Utils.toFileName(fileId) + extName;   
        case FileUsedType.GAME_VIEW_BIG:
	            return "ph/view/big" + Utils.toPath("/", fileId) + "/"
	                    + Utils.toFileName(fileId) + extName;      
		case FileUsedType.VIDEO:
			return "vo/fl" + Utils.toPath("/", fileId) + "/"
					+ Utils.toFileName(fileId) + extName;	
		case FileUsedType.VIDEO_IMAGE:
			return "vo/ph" + Utils.toPath("/", fileId) + "/"
					+ Utils.toFileName(fileId) + extName;		
		case FileUsedType.GAME_BACKGROUD:
			return "ph/back" + Utils.toPath("/", fileId) + "/"
					+ Utils.toFileName(fileId) + extName;
		case FileUsedType.GAME_PHOTO_OLD:
			return "ph/old" + Utils.toPath("/", fileId) + "/"
					+ Utils.toFileName(fileId) + "/";		
		case FileUsedType.FILE:
			return "fl" + Utils.toPath("/", fileId) + "/"
					+ Utils.toFileName(fileId) + extName;
		case FileUsedType.ADVER_PHOTO:
			return "ad" + Utils.toPath("/", fileId) + "/"
					+ Utils.toFileName(fileId) + extName;
		case FileUsedType.ALBUM_PHOTO:
			return "ab" + Utils.toPath("/", fileId) + "/"
					+ Utils.toFileName(fileId) + extName;
		case FileUsedType.ALBUM_PHOTO_SML:
			return "ab/sml" + Utils.toPath("/", fileId) + "/"
					+ Utils.toFileName(fileId) + extName;	
		case FileUsedType.ALBUM_PHOTO_MID:
			return "ab/mid" + Utils.toPath("/", fileId) + "/"
					+ Utils.toFileName(fileId) + extName;	
		case FileUsedType.ALBUM_PHOTO_BIG:
			return "ab/big" + Utils.toPath("/", fileId) + "/"
					+ Utils.toFileName(fileId) + extName;	
		case FileUsedType.HEAD_DEFAULT:
			return "hd/def" + Utils.toPath("/", fileId) + "/"
					+ Utils.toFileName(fileId) + extName;	
			
        case FileUsedType.CMS:
            return "cms/" + Utils.toDateString(new Date(), "yyyy/MM/dd") 
                    + "/" + fileName; 	
        case FileUsedType.ACTIVITY:
            return "act/" + Utils.toDateString(new Date(), "yyyy/MM/dd") 
                    + "/" + fileName;       
		default:
			throw new ExceptionCommon(-1,
					fileType.toString());
		}
	}
	
}
